/************************************************************************
                                                                     
   Xceed Ultimate ListBox for Silverlight                                                                                                                                            
   Copyright (C) 2010 Xceed Software Inc.    
                                                                     
   This program is provided to you under the terms of the GNU General Public  
   License version 2 as published by the Free Software Foundation. 
        
   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY, without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along 
   with this program, if not, write to the Free Software Foundation, Inc., 
   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

   This program can be provided to you by Xceed Software Inc. under a
   proprietary commercial license agreement for use in non-Open Source
   projects. Visit Xceed.com to find the commercial edition of 
   Xceed Ultimate ListBox for Silverlight.                                    
                                                                      
 **********************************************************************/

using System.Windows;
using System.Windows.Markup;
using System;

namespace Xceed.Silverlight.DragDrop
{
  public class DraggedElementConfiguration : DependencyObject
  {
    #region DefaultElementTemplate Private Static Property

    private static DataTemplate DefaultElementTemplate
    {
      get
      {
        if( DefaultElementTemplateCache == null )
        {
          string imageTemplate = "<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:xcdragdrop='http://schemas.xceed.com/silverlight/xaml/controls' ><Image Source='{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(xcdragdrop:DragDropAdornerManager.DraggedElementImageSource)}'/></DataTemplate>";

#if SILVERLIGHT
          DefaultElementTemplateCache = XamlReader.Load( imageTemplate ) as DataTemplate;
#else
          DefaultElementTemplateCache = XamlReader.Parse( imageTemplate ) as DataTemplate;
#endif
        }

        return DefaultElementTemplateCache;
      }
    }

    private static DataTemplate DefaultElementTemplateCache;

    #endregion

    #region ElementTemplate Public Property

    public static readonly DependencyProperty ElementTemplateProperty = DependencyProperty.Register(
      "ElementTemplate",
      typeof( DataTemplate ),
      typeof( DraggedElementConfiguration ),
      new PropertyMetadata( DraggedElementConfiguration.DefaultElementTemplate ) );

    public DataTemplate ElementTemplate
    {
      get
      {
        return ( DataTemplate )this.GetValue( DraggedElementConfiguration.ElementTemplateProperty );
      }
      set
      {
        this.SetValue( DraggedElementConfiguration.ElementTemplateProperty, value );
      }
    }

    #endregion

    #region DisplaySiblingElements Property

    public static readonly DependencyProperty DisplaySiblingElementsProperty = DependencyProperty.Register(
      "DisplaySiblingElements",
      typeof( bool ),
      typeof( DraggedElementConfiguration ),
      new PropertyMetadata( true ) );

    public bool DisplaySiblingElements
    {
      get
      {
        return ( bool )this.GetValue( DraggedElementConfiguration.DisplaySiblingElementsProperty );
      }
      set
      {
        this.SetValue( DraggedElementConfiguration.DisplaySiblingElementsProperty, value );
      }
    }

    #endregion

    #region PositionAdornerRelativeToElement Property

    public static readonly DependencyProperty PositionAdornerRelativeToElementProperty = DependencyProperty.Register(
      "PositionAdornerRelativeToElement",
      typeof( bool ),
      typeof( DraggedElementConfiguration ),
      new PropertyMetadata( true ) );

    public bool PositionAdornerRelativeToElement
    {
      get
      {
        return ( bool )this.GetValue( DraggedElementConfiguration.PositionAdornerRelativeToElementProperty );
      }
      set
      {
        this.SetValue( DraggedElementConfiguration.PositionAdornerRelativeToElementProperty, value );
      }
    }

    #endregion

    #region SiblingElementTemplate Public Property

    public static readonly DependencyProperty SiblingElementTemplateProperty = DependencyProperty.Register(
      "SiblingElementTemplate",
      typeof( DataTemplate ),
      typeof( DraggedElementConfiguration ),
      new PropertyMetadata( DraggedElementConfiguration.DefaultElementTemplate ) );

    public DataTemplate SiblingElementTemplate
    {
      get
      {
        return ( DataTemplate )this.GetValue( DraggedElementConfiguration.SiblingElementTemplateProperty );
      }
      set
      {
        this.SetValue( DraggedElementConfiguration.SiblingElementTemplateProperty, value );
      }
    }

    #endregion

    #region CanDropCursor Property

    public static readonly DependencyProperty CanDropCursorProperty =
        DependencyProperty.Register( "CanDropCursor", typeof( DragDropCursor ), typeof( DraggedElementConfiguration ), new PropertyMetadata( DragDropCursor.Arrow ) );


    public DragDropCursor CanDropCursor
    {
      get
      {
        return ( DragDropCursor )this.GetValue( DraggedElementConfiguration.CanDropCursorProperty );
      }
      set
      {
        this.SetValue( DraggedElementConfiguration.CanDropCursorProperty, value );
      }
    }

    #endregion

    #region NoDropCursor Property

    public static readonly DependencyProperty NoDropCursorProperty =
        DependencyProperty.Register( "NoDropCursor", typeof( DragDropCursor ), typeof( DraggedElementConfiguration ), new PropertyMetadata( DragDropCursor.No ) );


    public DragDropCursor NoDropCursor
    {
      get
      {
        return ( DragDropCursor )this.GetValue( DraggedElementConfiguration.NoDropCursorProperty );
      }
      set
      {
        this.SetValue( DraggedElementConfiguration.NoDropCursorProperty, value );
      }
    }

    #endregion

    #region CanDropCursorTemplate Property

    public static readonly DependencyProperty CanDropCursorTemplateProperty =
        DependencyProperty.Register( "CanDropCursorTemplate", typeof( DataTemplate ), typeof( DraggedElementConfiguration ), new PropertyMetadata( null ) );

    public DataTemplate CanDropCursorTemplate
    {
      get
      {
        return ( DataTemplate )this.GetValue( DraggedElementConfiguration.CanDropCursorTemplateProperty );
      }
      set
      {
        this.SetValue( DraggedElementConfiguration.CanDropCursorTemplateProperty, value );
      }
    }

    #endregion

    #region NoDropCursorTemplate Property

    public static readonly DependencyProperty NoDropCursorTemplateProperty =
        DependencyProperty.Register( "NoDropCursorTemplate", typeof( DataTemplate ), typeof( DraggedElementConfiguration ), new PropertyMetadata( null ) );

    public DataTemplate NoDropCursorTemplate
    {
      get
      {
        return ( DataTemplate )this.GetValue( DraggedElementConfiguration.NoDropCursorTemplateProperty );
      }
      set
      {
        this.SetValue( DraggedElementConfiguration.NoDropCursorTemplateProperty, value );
      }
    }

    #endregion

    #region ElementFadeInDuration Property

    public static readonly DependencyProperty ElementFadeInDurationProperty = DependencyProperty.Register(
      "ElementFadeInDuration",
      typeof( Nullable<TimeSpan> ),
      typeof( DraggedElementConfiguration ),
      new PropertyMetadata( null ) );

    public Nullable<TimeSpan> ElementFadeInDuration
    {
      get
      {
        return ( Nullable<TimeSpan> )this.GetValue( DraggedElementConfiguration.ElementFadeInDurationProperty );
      }
      set
      {
        this.SetValue( DraggedElementConfiguration.ElementFadeInDurationProperty, value );
      }
    }

    #endregion

    #region ElementFadeOutDuration Property

    public static readonly DependencyProperty ElementFadeOutDurationProperty = DependencyProperty.Register(
      "ElementFadeOutDuration",
      typeof( Nullable<TimeSpan> ),
      typeof( DraggedElementConfiguration ),
      new PropertyMetadata( null ) );

    public Nullable<TimeSpan> ElementFadeOutDuration
    {
      get
      {
        return ( Nullable<TimeSpan> )this.GetValue( DraggedElementConfiguration.ElementFadeOutDurationProperty );
      }
      set
      {
        this.SetValue( DraggedElementConfiguration.ElementFadeOutDurationProperty, value );
      }
    }

    #endregion

    #region ApplyDraggedElementRenderTransform Property

    public static readonly DependencyProperty ApplyDraggedElementRenderTransformProperty = DependencyProperty.Register(
      "ApplyDraggedElementRenderTransform",
      typeof( bool ),
      typeof( DraggedElementConfiguration ),
      new PropertyMetadata( ( bool )true ) );

    public bool ApplyDraggedElementRenderTransform
    {
      get
      {
        return ( bool )this.GetValue( DraggedElementConfiguration.ApplyDraggedElementRenderTransformProperty );
      }
      set
      {
        this.SetValue( DraggedElementConfiguration.ApplyDraggedElementRenderTransformProperty, value );
      }
    }

    #endregion

    #region Internal Methods

    internal TimeSpan GetDraggedElementFadeInDuration()
    {
      if( this.ElementFadeInDuration.HasValue )
      {
        return ( TimeSpan )this.ElementFadeInDuration.Value;
      }

      return TimeSpan.FromMilliseconds( 250 );
    }

    internal TimeSpan GetDraggedElementFadeOutDuration()
    {
      if( this.ElementFadeOutDuration.HasValue )
      {
        return ( TimeSpan )this.ElementFadeOutDuration.Value;
      }

      return TimeSpan.FromMilliseconds( 250 );
    }

    #endregion
  }
}
